<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>布署 | 欢迎学习django课程</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../part6/7.html" />
    
    
    <link rel="prev" href="../part6/5.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="6.5"
        data-chapter-title="布署"
        data-filepath="part6/6.md"
        data-basepath=".."
        data-revision="Tue Jan 03 2017 08:43:08 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="part1/1.html">
            
                
                    <a href="../part1/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        入门
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="part1/2.html">
            
                
                    <a href="../part1/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        搭建开发环境
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="part1/3.html">
            
                
                    <a href="../part1/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        设计模型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="part1/4.html">
            
                
                    <a href="../part1/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        管理站点
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="part1/5.html">
            
                
                    <a href="../part1/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="part1/6.html">
            
                
                    <a href="../part1/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        模板
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="part1/7.html">
            
                
                    <a href="../part1/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="part2/1.html">
            
                
                    <a href="../part2/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        模型
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="part2/2.html">
            
                
                    <a href="../part2/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        定义模型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="part2/3.html">
            
                
                    <a href="../part2/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        模型成员
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="part2/4.html">
            
                
                    <a href="../part2/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        模型查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="part2/5.html">
            
                
                    <a href="../part2/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        自连接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="part2/6.html">
            
                
                    <a href="../part2/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="part3/1.html">
            
                
                    <a href="../part3/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        视图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="part3/2.html">
            
                
                    <a href="../part3/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        URLconf
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="part3/3.html">
            
                
                    <a href="../part3/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        视图函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="part3/4.html">
            
                
                    <a href="../part3/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Request对象
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="part3/4_1.html">
            
                
                    <a href="../part3/4_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        QueryDict对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="part3/4_2.html">
            
                
                    <a href="../part3/4_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        GET属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="part3/4_3.html">
            
                
                    <a href="../part3/4_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.3.</b>
                        
                        POST属性
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="part3/5.html">
            
                
                    <a href="../part3/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        Response对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="part3/6.html">
            
                
                    <a href="../part3/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        状态保持
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="part3/7.html">
            
                
                    <a href="../part3/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="part4/1.html">
            
                
                    <a href="../part4/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        模板
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="part4/2.html">
            
                
                    <a href="../part4/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        定义模板
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="part4/3.html">
            
                
                    <a href="../part4/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        模板继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="part4/4.html">
            
                
                    <a href="../part4/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        HTML转义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="part4/5.html">
            
                
                    <a href="../part4/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        CSRF
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="part4/6.html">
            
                
                    <a href="../part4/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        验证码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="part4/7.html">
            
                
                    <a href="../part4/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="part5/1.html">
            
                
                    <a href="../part5/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="part5/2.html">
            
                
                    <a href="../part5/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        静态文件处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="part5/3.html">
            
                
                    <a href="../part5/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        中间件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="part5/4.html">
            
                
                    <a href="../part5/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        上传图片
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="part5/5.html">
            
                
                    <a href="../part5/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        Admin站点
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="part5/6.html">
            
                
                    <a href="../part5/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        分页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="part5/7.html">
            
                
                    <a href="../part5/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        ajax
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="part5/8.html">
            
                
                    <a href="../part5/8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="part6/1.html">
            
                
                    <a href="../part6/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        第三方
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="part6/2.html">
            
                
                    <a href="../part6/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        富文本编辑器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="part6/3.html">
            
                
                    <a href="../part6/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        缓存
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="part6/4.html">
            
                
                    <a href="../part6/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        全文检索
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="part6/5.html">
            
                
                    <a href="../part6/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        celery
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="6.5" data-path="part6/6.html">
            
                
                    <a href="../part6/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        布署
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="part6/7.html">
            
                
                    <a href="../part6/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="part7/1.html">
            
                
                    <a href="../part7/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        Git与项目
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="part7/2.html">
            
                
                    <a href="../part7/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        Git简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.1" data-path="part7/2_2.html">
            
                
                    <a href="../part7/2_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.1.</b>
                        
                        远程仓库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.1.2" data-path="part7/2_1.html">
            
                
                    <a href="../part7/2_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.2.</b>
                        
                        本地仓库
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="part7/3.html">
            
                
                    <a href="../part7/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        项目设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="part7/4.html">
            
                
                    <a href="../part7/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        模型类设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="part7/5.html">
            
                
                    <a href="../part7/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        使用页面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="part7/6.html">
            
                
                    <a href="../part7/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >欢迎学习django课程</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5E03;&#x7F72;">&#x5E03;&#x7F72;</h1>
<ul>
<li>&#x4ECE;uwsgi&#x3001;nginx&#x3001;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x4E09;&#x4E2A;&#x65B9;&#x9762;&#x5904;&#x7406;</li>
</ul>
<h4 id="&#x670D;&#x52A1;&#x5668;&#x4ECB;&#x7ECD;">&#x670D;&#x52A1;&#x5668;&#x4ECB;&#x7ECD;</h4>
<ul>
<li>&#x670D;&#x52A1;&#x5668;&#xFF1A;&#x79C1;&#x6709;&#x670D;&#x52A1;&#x5668;&#x3001;&#x516C;&#x6709;&#x670D;&#x52A1;&#x5668;</li>
<li>&#x79C1;&#x6709;&#x670D;&#x52A1;&#x5668;&#xFF1A;&#x516C;&#x53F8;&#x81EA;&#x5DF1;&#x8D2D;&#x4E70;&#x3001;&#x81EA;&#x5DF1;&#x7EF4;&#x62A4;&#xFF0C;&#x53EA;&#x5E03;&#x7F72;&#x81EA;&#x5DF1;&#x7684;&#x5E94;&#x7528;&#xFF0C;&#x53EF;&#x4F9B;&#x516C;&#x53F8;&#x5185;&#x90E8;&#x6216;&#x5916;&#x7F51;&#x8BBF;&#x95EE;</li>
<li>&#x516C;&#x6709;&#x670D;&#x52A1;&#x5668;&#xFF1A;&#x96C6;&#x6210;&#x597D;&#x8FD0;&#x8425;&#x73AF;&#x5883;&#xFF0C;&#x9500;&#x552E;&#x7A7A;&#x95F4;&#x6216;&#x4E3B;&#x673A;&#xFF0C;&#x4F9B;&#x5176;&#x5E03;&#x7F72;&#x81EA;&#x5DF1;&#x7684;&#x5E94;&#x7528;</li>
<li>&#x79C1;&#x6709;&#x670D;&#x52A1;&#x5668;&#x6210;&#x672C;&#x9AD8;&#xFF0C;&#x9700;&#x8981;&#x4E13;&#x4E1A;&#x4EBA;&#x5458;&#x7EF4;&#x62A4;&#xFF0C;&#x9002;&#x5408;&#x5927;&#x516C;&#x53F8;&#x4F7F;&#x7528;</li>
<li>&#x516C;&#x6709;&#x670D;&#x52A1;&#x5668;&#x9002;&#x5408;&#x521D;&#x521B;&#x516C;&#x53F8;&#x4F7F;&#x7528;&#xFF0C;&#x6210;&#x672C;&#x4F4E;</li>
<li>&#x5E38;&#x7528;&#x7684;&#x516C;&#x6709;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x5982;&#x963F;&#x91CC;&#x4E91;&#x3001;&#x9752;&#x4E91;&#x7B49;&#xFF0C;&#x53EF;&#x6839;&#x636E;&#x9700;&#x8981;&#xFF0C;&#x6309;&#x6D41;&#x91CF;&#x6536;&#x8D39;&#x6216;&#x6309;&#x65F6;&#x95F4;&#x6536;&#x8D39;</li>
<li>&#x6B64;&#x5904;&#x7684;&#x670D;&#x52A1;&#x5668;&#x662F;&#x7269;&#x7406;&#x4E0A;&#x7684;&#x4E00;&#x53F0;&#x975E;&#x5E38;&#x9AD8;&#x3001;&#x7EBF;&#x8DEF;&#x5168;&#x3001;&#x8FD0;&#x884C;&#x7A33;&#x5B9A;&#x7684;&#x673A;&#x5668;</li>
</ul>
<h4 id="&#x670D;&#x52A1;&#x5668;&#x73AF;&#x5883;&#x914D;&#x7F6E;">&#x670D;&#x52A1;&#x5668;&#x73AF;&#x5883;&#x914D;&#x7F6E;</h4>
<ul>
<li>&#x5728;&#x672C;&#x5730;&#x7684;&#x865A;&#x62DF;&#x73AF;&#x5883;&#x4E2D;&#xFF0C;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x6267;&#x884C;&#x547D;&#x4EE4;&#x6536;&#x96C6;&#x6240;&#x6709;&#x5305;</li>
</ul>
<pre><code>pip freeze &gt; plist.txt
</code></pre><ul>
<li>&#x901A;&#x8FC7;ftp&#x8F6F;&#x4EF6;&#x5C06;&#x5F00;&#x53D1;&#x597D;&#x7684;&#x9879;&#x76EE;&#x4E0A;&#x4F20;&#x5230;&#x6B64;&#x670D;&#x52A1;&#x5668;&#x7684;&#x67D0;&#x4E2A;&#x76EE;&#x5F55;</li>
<li>&#x5B89;&#x88C5;&#x5E76;&#x521B;&#x5EFA;&#x865A;&#x62DF;&#x73AF;&#x5883;&#xFF0C;&#x5982;&#x679C;&#x5DF2;&#x6709;&#x5219;&#x8DF3;&#x8FC7;&#x6B64;&#x6B65;</li>
</ul>
<pre><code>sudo apt-get install python-virtualenv
sudo easy_install virtualenvwrapper
mkvirtualenv [&#x865A;&#x62DF;&#x73AF;&#x5883;&#x540D;&#x79F0;]
</code></pre><ul>
<li>&#x5728;&#x865A;&#x62DF;&#x73AF;&#x5883;&#x4E0A;&#x5DE5;&#x4F5C;&#xFF0C;&#x5B89;&#x88C5;&#x6240;&#x6709;&#x9700;&#x8981;&#x7684;&#x5305;</li>
</ul>
<pre><code>workon [&#x865A;&#x62DF;&#x73AF;&#x5883;&#x540D;&#x79F0;]
pip install -r plist.txt
</code></pre><ul>
<li>&#x66F4;&#x6539;settings.py&#x6587;&#x4EF6;</li>
</ul>
<pre><code>DEBUG = False
ALLOW_HOSTS=[&apos;*&apos;,]&#x8868;&#x793A;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x670D;&#x52A1;&#x5668;&#x7684;ip
</code></pre><ul>
<li>&#x542F;&#x52A8;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x8FD0;&#x884C;&#x6B63;&#x5E38;&#xFF0C;&#x4F46;&#x662F;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x65E0;&#x6CD5;&#x52A0;&#x8F7D;</li>
</ul>
<h4 id="wsgi">WSGI</h4>
<ul>
<li>python manage.py runserver&#xFF1A;&#x8FD9;&#x662F;&#x4E00;&#x6B3E;&#x9002;&#x5408;&#x5F00;&#x53D1;&#x9636;&#x6BB5;&#x4F7F;&#x7528;&#x7684;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4E0D;&#x9002;&#x5408;&#x8FD0;&#x884C;&#x5728;&#x771F;&#x5B9E;&#x7684;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E2D;</li>
<li>&#x5728;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E2D;&#x4F7F;&#x7528;WSGI</li>
<li>WSGI&#xFF1A;Web&#x670D;&#x52A1;&#x5668;&#x7F51;&#x5173;&#x63A5;&#x53E3;&#xFF0C;&#x82F1;&#x6587;&#x4E3A;Python Web Server Gateway Interface&#xFF0C;&#x7F29;&#x5199;&#x4E3A;WSGI&#xFF0C;&#x662F;Python&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x6216;&#x6846;&#x67B6;&#x548C;Web&#x670D;&#x52A1;&#x5668;&#x4E4B;&#x95F4;&#x7684;&#x4E00;&#x79CD;&#x63A5;&#x53E3;&#xFF0C;&#x88AB;&#x5E7F;&#x6CDB;&#x63A5;&#x53D7;</li>
<li>WSGI&#x6CA1;&#x6709;&#x5B98;&#x65B9;&#x7684;&#x5B9E;&#x73B0;, &#x56E0;&#x4E3A;WSGI&#x66F4;&#x50CF;&#x4E00;&#x4E2A;&#x534F;&#x8BAE;&#xFF0C;&#x53EA;&#x8981;&#x9075;&#x7167;&#x8FD9;&#x4E9B;&#x534F;&#x8BAE;,WSGI&#x5E94;&#x7528;(Application)&#x90FD;&#x53EF;&#x4EE5;&#x5728;&#x4EFB;&#x4F55;&#x670D;&#x52A1;&#x5668;(Server)&#x4E0A;&#x8FD0;&#x884C;</li>
<li>&#x547D;&#x4EE4;django-admin startproject&#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;wsgi.py&#x6587;&#x4EF6;&#xFF0C;&#x786E;&#x5B9A;&#x4E86;settings&#x3001;application&#x5BF9;&#x8C61;<ul>
<li>application&#x5BF9;&#x8C61;&#xFF1A;&#x5728;Python&#x6A21;&#x5757;&#x4E2D;&#x4F7F;&#x7528;application&#x5BF9;&#x8C61;&#x4E0E;&#x5E94;&#x7528;&#x670D;&#x52A1;&#x5668;&#x4EA4;&#x4E92;</li>
<li>settings&#x6A21;&#x5757;&#xFF1A;Django&#x9700;&#x8981;&#x5BFC;&#x5165;settings&#x6A21;&#x5757;&#xFF0C;&#x8FD9;&#x91CC;&#x662F;&#x5E94;&#x7528;&#x5B9A;&#x4E49;&#x7684;&#x5730;&#x65B9;</li>
</ul>
</li>
<li>&#x6B64;&#x5904;&#x7684;&#x670D;&#x52A1;&#x5668;&#x662F;&#x4E00;&#x4E2A;&#x8F6F;&#x4EF6;&#xFF0C;&#x53EF;&#x4EE5;&#x76D1;&#x542C;&#x7F51;&#x5361;&#x7AEF;&#x53E3;&#x3001;&#x9075;&#x4ECE;&#x7F51;&#x7EDC;&#x5C42;&#x4F20;&#x8F93;&#x534F;&#x8BAE;&#xFF0C;&#x6536;&#x53D1;http&#x534F;&#x8BAE;&#x7EA7;&#x522B;&#x7684;&#x6570;&#x636E;</li>
</ul>
<h4 id="uwsgi">uWSGI</h4>
<ul>
<li>uWSGI&#x5B9E;&#x73B0;&#x4E86;WSGI&#x7684;&#x6240;&#x6709;&#x63A5;&#x53E3;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x5FEB;&#x901F;&#x3001;&#x81EA;&#x6211;&#x4FEE;&#x590D;&#x3001;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x548C;&#x7CFB;&#x7EDF;&#x7BA1;&#x7406;&#x5458;&#x53CB;&#x597D;&#x7684;&#x670D;&#x52A1;&#x5668;</li>
<li>uWSGI&#x4EE3;&#x7801;&#x5B8C;&#x5168;&#x7528;C&#x7F16;&#x5199;</li>
<li>&#x5B89;&#x88C5;uWSGI</li>
</ul>
<pre><code>pip install uwsgi
</code></pre><ul>
<li>&#x914D;&#x7F6E;uWSGI&#xFF0C;&#x5728;&#x9879;&#x76EE;&#x4E2D;&#x65B0;&#x5EFA;&#x6587;&#x4EF6;uwsgi.ini&#xFF0C;&#x7F16;&#x5199;&#x5982;&#x4E0B;&#x914D;&#x7F6E;</li>
</ul>
<pre><code>[uwsgi]
socket=&#x5916;&#x7F51;ip:&#x7AEF;&#x53E3;&#xFF08;&#x4F7F;&#x7528;nginx&#x8FDE;&#x63A5;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;socket&#xFF09;
http=&#x5916;&#x7F51;ip:&#x7AEF;&#x53E3;&#xFF08;&#x76F4;&#x63A5;&#x505A;web&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4F7F;&#x7528;http&#xFF09;
chdir=&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;
wsgi-file=&#x9879;&#x76EE;&#x4E2D;wsgi.py&#x6587;&#x4EF6;&#x7684;&#x76EE;&#x5F55;&#xFF0C;&#x76F8;&#x5BF9;&#x4E8E;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;
processes=4
threads=2
master=True
pidfile=uwsgi.pid
daemonize=uswgi.log
</code></pre><ul>
<li>&#x542F;&#x52A8;&#xFF1A;uwsgi --ini uwsgi.ini</li>
<li>&#x505C;&#x6B62;&#xFF1A;uwsgi --stop uwsgi.pid</li>
<li>&#x91CD;&#x542F;&#xFF1A;uwsgi --reload uwsgi.pid</li>
<li>&#x4F7F;&#x7528;http&#x534F;&#x8BAE;&#x67E5;&#x770B;&#x7F51;&#x7AD9;&#x8FD0;&#x884C;&#x60C5;&#x51B5;&#xFF0C;&#x8FD0;&#x884C;&#x6B63;&#x5E38;&#xFF0C;&#x4F46;&#x662F;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x65E0;&#x6CD5;&#x52A0;&#x8F7D;</li>
</ul>
<h4 id="nginx">nginx</h4>
<ul>
<li>&#x4F7F;&#x7528;nginx&#x7684;&#x4F5C;&#x7528;<ul>
<li>&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#xFF1A;&#x591A;&#x53F0;&#x670D;&#x52A1;&#x5668;&#x8F6E;&#x6D41;&#x5904;&#x7406;&#x8BF7;&#x6C42;</li>
<li>&#x53CD;&#x5C04;&#x4EE3;&#x7406;&#xFF1A;&#x9690;&#x85CF;&#x771F;&#x5B9E;&#x670D;&#x52A1;&#x5668;</li>
</ul>
</li>
<li>&#x5B9E;&#x73B0;&#x6784;&#x67B6;&#xFF1A;&#x5BA2;&#x6237;&#x7AEF;&#x8BF7;&#x6C42;nginx&#xFF0C;&#x518D;&#x7531;nginx&#x8BF7;&#x6C42;uwsgi&#xFF0C;&#x8FD0;&#x884C;django&#x6846;&#x67B6;&#x4E0B;&#x7684;python&#x4EE3;&#x7801;</li>
<li>nginx+uwsgi&#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x5176;&#x5B83;&#x6846;&#x67B6;&#x7684;python web&#x4EE3;&#x7801;&#xFF0C;&#x4E0D;&#x9650;&#x4E8E;django</li>
<li>&#x5230;&#x5B98;&#x7F51;&#x4E0B;&#x8F7D;nginx&#x538B;&#x7F29;&#x6587;&#x4EF6;&#x6216;&#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x5B89;&#x88C5;</li>
</ul>
<pre><code>sudo apt-get nginx
</code></pre><ul>
<li>&#x8FD9;&#x91CC;&#x4EE5;&#x4E0B;&#x8F7D;&#x538B;&#x7F29;&#x6587;&#x4EF6;&#x4E3A;&#x4F8B;&#x6F14;&#x793A;</li>
</ul>
<pre><code>&#x89E3;&#x538B;&#x7F29;&#xFF1A;
tar zxvf nginx-1.6.3.tar.gz

&#x8FDB;&#x5165;nginx-1.6.3&#x76EE;&#x5F55;&#x4F9D;&#x6B21;&#x6267;&#x884C;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#x8FDB;&#x884C;&#x5B89;&#x88C5;&#xFF1A;
./configure
make
sudo make install
</code></pre><ul>
<li>&#x9ED8;&#x8BA4;&#x5B89;&#x88C5;&#x5230;/usr/local/nginx&#x76EE;&#x5F55;&#xFF0C;&#x8FDB;&#x5165;&#x6B64;&#x76EE;&#x5F55;&#x6267;&#x884C;&#x547D;&#x4EE4;</li>
<li>&#x67E5;&#x770B;&#x7248;&#x672C;&#xFF1A;sudo sbin/nginx -v</li>
<li>&#x542F;&#x52A8;&#xFF1A;sudo sbin/nginx</li>
<li>&#x505C;&#x6B62;&#xFF1A;sudo sbin/nginx -s stop</li>
<li>&#x91CD;&#x542F;&#xFF1A;sudo sbin/nginx -s reload</li>
<li>&#x901A;&#x8FC7;&#x6D4F;&#x89C8;&#x5668;&#x67E5;&#x770B;nginx&#x8FD0;&#x884C;&#x7ED3;&#x679C;</li>
<li>&#x6307;&#x5411;uwsgi&#x9879;&#x76EE;&#xFF1A;&#x7F16;&#x8F91;conf/nginx.conf&#x6587;&#x4EF6;</li>
</ul>
<pre><code>sudo conf/nginx.conf

&#x5728;server&#x4E0B;&#x6DFB;&#x52A0;&#x65B0;&#x7684;location&#x9879;&#xFF0C;&#x6307;&#x5411;uwsgi&#x7684;ip&#x4E0E;&#x7AEF;&#x53E3;
location / {
    include uwsgi_params;&#x5C06;&#x6240;&#x6709;&#x7684;&#x53C2;&#x6570;&#x8F6C;&#x5230;uwsgi&#x4E0B;
    uwsgi_pass uwsgi&#x7684;ip&#x4E0E;&#x7AEF;&#x53E3;;
}
</code></pre><ul>
<li><font color="red">&#x4FEE;&#x6539;uwsgi.ini&#x6587;&#x4EF6;&#xFF0C;&#x542F;&#x52A8;socket&#xFF0C;&#x7981;&#x7528;http</font></li>
<li>&#x91CD;&#x542F;nginx&#x3001;uwsgi</li>
<li>&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x67E5;&#x770B;&#x9879;&#x76EE;&#xFF0C;&#x53D1;&#x73B0;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x52A0;&#x8F7D;&#x4E0D;&#x6B63;&#x5E38;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x89E3;&#x51B3;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x7684;&#x95EE;&#x9898;</li>
</ul>
<h4 id="&#x9759;&#x6001;&#x6587;&#x4EF6;">&#x9759;&#x6001;&#x6587;&#x4EF6;</h4>
<ul>
<li>&#x9759;&#x6001;&#x6587;&#x4EF6;&#x4E00;&#x76F4;&#x90FD;&#x627E;&#x4E0D;&#x5230;&#xFF0C;&#x73B0;&#x5728;&#x7EC8;&#x4E8E;&#x53EF;&#x4EE5;&#x89E3;&#x51B3;&#x4E86;</li>
<li>&#x6240;&#x6709;&#x7684;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x90FD;&#x4F1A;&#x7531;nginx&#x5904;&#x7406;&#xFF0C;&#x4E0D;&#x4F1A;&#x5C06;&#x8BF7;&#x6C42;&#x8F6C;&#x5230;uwsgi</li>
<li>&#x914D;&#x7F6E;nginx&#x7684;&#x9759;&#x6001;&#x9879;&#xFF0C;&#x6253;&#x5F00;conf/nginx.conf&#x6587;&#x4EF6;&#xFF0C;&#x627E;&#x5230;server&#xFF0C;&#x6DFB;&#x52A0;&#x65B0;location</li>
</ul>
<pre><code>location /static {
    alias /var/www/test5/static/;
}
</code></pre><ul>
<li>&#x5728;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x521B;&#x5EFA;&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#x201C;/var/www/test5/&#x201D;</li>
<li>&#x4FEE;&#x6539;&#x76EE;&#x5F55;&#x6743;&#x9650;</li>
</ul>
<pre><code>sudo chmod 777 /var/www/test5
</code></pre><ul>
<li>&#x521B;&#x5EFA;static&#x76EE;&#x5F55;&#xFF0C;&#x6CE8;&#x610F;&#x987A;&#x5E8F;&#x662F;&#x5148;&#x5206;&#x914D;&#x6743;&#x9650;&#xFF0C;&#x518D;&#x521B;&#x5EFA;&#x76EE;&#x5F55;</li>
</ul>
<pre><code>mkdir static
</code></pre><ul>
<li>&#x6700;&#x7EC8;&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#x5982;&#x4E0B;&#x56FE;&#xFF1A;</li>
</ul>
<p><img src="images/static.png" alt="static"></p>
<ul>
<li>&#x4FEE;&#x6539;settings.py&#x6587;&#x4EF6;</li>
</ul>
<pre><code>STATIC_ROOT=&apos;/var/www/test5/static/&apos;
STATIC_URL=&apos;/static/&apos;
</code></pre><ul>
<li>&#x6536;&#x96C6;&#x6240;&#x6709;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x5230;static_root&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#xFF1A;python manage.py collectstatic</li>
<li>&#x91CD;&#x542F;nginx&#x3001;uwsgi</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../part6/5.html" class="navigation navigation-prev " aria-label="Previous page: celery"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../part6/7.html" class="navigation navigation-next " aria-label="Next page: 总结与作业"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
